layui.config({
    base: '../../static/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['upload','layer','form','jquery'], function() {
    var $ = layui.jquery;
    var upload = layui.upload;
    var form = layui.form;
    var layer = layui.layer;
    var id=urlQuery("id");

    if(id==null||id==''){
        id = null;
        //添加
    }else {
        $.ajax({
            url: "/${table.lowerClassName}/getInfo",
            data: {id: id},
            type: "get",
            success: function (result) {
                var ${table.lowerClassName} = result.data;
                <#list table.columns as column>
                $('#${column.filedName}').val(${table.lowerClassName}.${column.filedName});//${column.remakes}
                </#list>
                form.render("select");
            },
            error: function () {
                alert("请求失败")
            }
        })
    }


    //监听提交
    form.on('submit(demo1)', function(data){
        var data=data.field;
        <#list table.columns as column>
            if(data.${column.filedName} == null || data.${column.filedName} == ""){
                layer.msg("请输入${column.remakes}",{icon:2,time:2000,shade:0.2});
                return false;
            }
        </#list>
        $.ajax({
            url:"/${table.lowerClassName}/addAndUpdate",
            type:"post",
            data: data,
            success:function (result) {
                if(result.code==0){
                    layer.msg(result.message, {icon: 1,time:2000,shade:0.2});
                    setInterval(function () {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                    window.parent.location.reload();
                    },2000)
                }else {
                    layer.msg(result.message, {icon: 2,time:2000,shade:0.2});
                }
            }
        });
        return false;
    });

});